#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
    , m_ptimer(new QTimer)
{
    ui->setupUi(this);

    m_ptimer->setInterval(1000);

    connect(m_ptimer, &QTimer::timeout, this, &Widget::time_out);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::mousePressEvent(QMouseEvent *event){
    m_bg = event->pos();

    qDebug() << m_bg;
}


void Widget::mouseReleaseEvent(QMouseEvent *event){
    move(pos() + event->pos() - m_bg);
}


void Widget::keyPressEvent(QKeyEvent *event){
    qDebug() << event->key();
    return ;
}

void Widget::paintEvent(QPaintEvent *evnet){
    QPainter painter(this);

    QPen pen(Qt::red);
    pen.setWidth(5);

    painter.setPen(pen);
    painter.drawRect(rect());

    return;

}

void Widget::time_out(){
    m_ptimer->start();
}
